package com.example.myapplication3;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.TextView;

import com.example.myapplication3.base.BaseActivity;
import com.example.myapplication3.home.HomeActivity;
import com.example.myapplication3.splash.SplashActivity;


public class MainActivity extends BaseActivity {

//       练习  主线程更新UI-----------------------------------------------------------
//        Handler handler = new Handler(Looper.getMainLooper()) {
//            @Override
//            public void handleMessage(@NonNull Message msg) {
//                if (msg.what == 1) {
//                    textView.setText(msg.obj + "");
//                }
//                super.handleMessage(msg);
//            }
//        };
//
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                try {
//                    Thread.sleep(2000);
//                }catch (Exception e){
//                    e.printStackTrace();
//                }
//                Message msg =Message.obtain();
//                msg.what=1;
//                msg.obj="我是消息";
//                handler.handleMessage(msg);
//            }
//        }).start();
//       练习  主线程更新UI-----------------------------------------------------------

// 使用示例
//        子线程创建自己的消息循环======================================================
//        WorkerThread worker = new WorkerThread();
//        worker.start();
// 稍后发送任务
//        new Handler(Looper.getMainLooper()).postDelayed(() -> {
//            worker.sendTask("第一个任务");
//            worker.sendTask("第二个任务");
//        }, 1000);
//        子线程创建自己的消息循环======================================================
private TextView textView;
    @Override
    public int getLayoutMain() {
        return R.layout.activity_main;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        textView=findViewById(R.id.textview);
        Animation animation = AnimationUtils.loadAnimation(this,R.anim.animation_text);
        textView.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }
            @Override
            public void onAnimationEnd(Animation animation) {
                SharedPreferences sp= getSharedPreferences("splash_sp", Context.MODE_PRIVATE);
                boolean isFirstlaunch = sp.getBoolean("FirstLaunch",true);
                Intent intent = new Intent();
                if (isFirstlaunch){
                    intent.setClass(MainActivity.this, SplashActivity.class);
                } else {
                    intent.setClass(MainActivity.this, HomeActivity.class);
                }
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    @Override
    public void initListener() {

    }


}
